﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Web;


namespace ClassLibrary1
{
    
    public class Users
    {
        DBHelper dbh = new DBHelper();
        public bool CheckLogin(string id, string pass,bool type)
        {
            bool flag = false;
            string sql = "SELECT * FROM Users where userID='" + id + "' and userPassword='" + pass + "' and Type='"+ type+"'";
            SqlDataReader reader = dbh.executeQuerySql(sql);
            if (reader.Read())
            {
                User us = new User();
                us.type = bool.Parse(reader["Type"].ToString());
                flag = true;
            }
            return flag;
        }

        public void CreateAcc(string user, string pass, string first, string last, string dob, bool gen, int phone, string address, string email,bool type)
        {
            string sql = "INSERT INTO Users VALUES('" + user + "','" + pass + "','" + first + "','" + last + "','" + dob + "','" + gen + "','" + phone + "','" + address + "','" + email +  "','" + type +"')";
            dbh.executeNonQuery(sql);
        }

        public bool CheckCreat(string user)
        {
            bool flag = false;
            string sql = "SELECT * FROM Users WHERE userID='" + user + "'";
            SqlDataReader reader = dbh.executeQuerySql(sql);
            if (reader.Read())
            {
                flag = true;
            }
            return flag;
        }

        public User GetUserByID(string userid)
        {
            string sql = "SELECT * FROM Users WHERE userID='" + userid + "'";
            SqlDataReader reader = dbh.executeQuerySql(sql);
            User user = new User();
            if (reader.Read())
            {
                user.userid = reader["userID"].ToString();
                user.password = reader["userPassword"].ToString();
                user.firstname = reader["firstName"].ToString();
                user.lastname = reader["lastName"].ToString();
                user.dob = reader["Birthday"].ToString();
                user.gender = bool.Parse(reader["Gender"].ToString());
                user.phone = Int32.Parse(reader["Phone"].ToString());
                user.address = reader["Address"].ToString();
                user.email = reader["Email"].ToString();
            }
            return user;
        }
    }

    

}
